package com.cnswhy.cloud.server.merchant.controller.split;

import com.cnswhy.cloud.common.logging.uitls.MDCUtil;
import com.cnswhy.cloud.common.rabbitmq.service.MessageService;
import com.cnswhy.cloud.server.common.entity.constant.AmqpExchange;
import com.cnswhy.cloud.server.common.entity.mq.CpsOrderQueryMQ;
import com.cnswhy.cloud.server.common.entity.mq.SplitAccountMQ;
import com.cnswhy.cloud.server.core.entity.SplitTransRecord;
import com.cnswhy.cloud.server.core.dto.SplitTransRecordSaveDTO;
import com.cnswhy.cloud.server.core.dto.SplitTransRecordUpdateDTO;
import com.cnswhy.cloud.server.core.dto.SplitTransRecordPageDTO;
import com.cnswhy.cloud.server.core.service.SplitTransRecordService;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.cnswhy.cloud.common.core.base.controller.SuperController;
import com.cnswhy.cloud.common.core.base.R;
import com.cnswhy.cloud.server.merchant.dto.HomeDto;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
//import com.github.zuihou.security.annotation.PreAuth;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 
 * </p>
 *
 * @author cnswhy
 * @date 2021-02-02
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/splitTransRecord")
@Api(value = "SplitTransRecord", tags = "")
//@PreAuth(replace = "splitTransRecord:")
public class SplitTransRecordController extends SuperController<SplitTransRecordService, Long, SplitTransRecord, SplitTransRecordPageDTO, SplitTransRecordSaveDTO, SplitTransRecordUpdateDTO> {
    @Autowired
    MessageService messageService;
    @GetMapping("splitAccount")
    public R<Object> splitAccount(Long id) {
        SplitAccountMQ splitAccountMQ = SplitAccountMQ.builder().splitTransRecordId(id).build();
        splitAccountMQ.setTraceId(MDCUtil.getTraceId());
        messageService.sendQueueByObject(AmqpExchange.SPLIT_ACCOUNT_MESSAGE, splitAccountMQ);

        return R.success("成功");
    }
    @GetMapping("split")
    public R<Object> split(Long id) {
        CpsOrderQueryMQ cpsOrderQueryMQ = CpsOrderQueryMQ.builder().cpsId(id).build();
        messageService.sendQueueByObject(AmqpExchange.CPS_ORDER_SPLIT_MESSAGE, cpsOrderQueryMQ);

        return R.success("成功");
    }
    /**/
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<SplitTransRecord> splitTransRecordList = list.stream().map((map) -> {
            SplitTransRecord splitTransRecord = SplitTransRecord.builder().build();
            return splitTransRecord;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(splitTransRecordList));
    }
}
